﻿using System;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using OmegaEngine;

namespace OmegaEngine
{
    public class GUIDynamicLabel : GUIActor
    {
        string text = "";
        SpriteFont font = Engine.DefaultFont;
        Color color = Color.White;
        string label = "";
        GUIValueHandler value = null;

        // 
        // public delegate string ValueHandler();
        // public event ValueHandler Value;

        public GUIDynamicLabel(string Text, GUIValueHandler Value)
            : base(Engine.DefaultFont.MeasureString(Text))
        {
            SetupLabel(Text, Value, Engine.DefaultFont, Color.White);
        }

        public GUIDynamicLabel(string Text, GUIValueHandler Value, GameScreen Parent)
            : base(Engine.DefaultFont.MeasureString(Text), Parent)
        {
            SetupLabel(Text, Value, Engine.DefaultFont, Color.White);
        }

        public GUIDynamicLabel(string Text, GUIValueHandler Value, SpriteFont Font)
            : base(Font.MeasureString(Text))
        {
            SetupLabel(Text, Value, Font, Color.White);
        }

        public GUIDynamicLabel(string Text, GUIValueHandler Value, SpriteFont Font, GameScreen Parent)
            : base(Font.MeasureString(Text), Parent)
        {
            SetupLabel(Text, Value, Font, Color.White);
        }

        public GUIDynamicLabel(string Text, GUIValueHandler Value, SpriteFont Font, int PositionX, int PositionY)
            : base(Font.MeasureString(Text), PositionX, PositionY)
        {
            SetupLabel(Text, Value, Font, Color.White);
        }

        public GUIDynamicLabel(string Text, GUIValueHandler Value, SpriteFont Font, int PositionX, int PositionY, GameScreen Parent)
            : base(Font.MeasureString(Text), PositionX, PositionY, Parent)
        {
            SetupLabel(Text, Value, Font, Color.White);
        }

        public GUIDynamicLabel(string Text, GUIValueHandler Value, SpriteFont Font, int PositionX, int PositionY, Color Color)
            : base(Font.MeasureString(Text), PositionX, PositionY)
        {
            SetupLabel(Text, Value, Font, Color);
        }

        public GUIDynamicLabel(string Text, GUIValueHandler Value, SpriteFont Font, int PositionX, int PositionY, Color Color, GameScreen Parent)
            : base(Font.MeasureString(Text), PositionX, PositionY, Parent)
        {
            SetupLabel(Text, Value, Font, Color);
        }

        void SetupLabel(string Text, GUIValueHandler Value, SpriteFont Font, Color Color)
        {
            this.label = Text;
            this.font = Font;
            this.color = Color;
            this.value += Value;
        }

        public override void Update()
        {
            this.text = this.label + this.value();
        }

        public override void Draw()
        {
            Engine.SpriteBatch.DrawString(this.font, this.text, new Vector2(this.positionX, this.positionY), this.color);
            base.Draw();
        }
    }
}
